﻿namespace DCHealthCheck.MvcWeb.Controllers {

    #region Usings
    using DCHealthCheck.Common;
    using DCHealthCheck.MvcWeb.Classes;
    using DCHealthCheck.MvcWeb.Classes.ViewModels;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading;
    using System.Web;
    using System.Web.Mvc; 
    #endregion

    public class ErrorController : Controller {

        public ActionResult AccessDenied(ErrorViewModel viewModel) {
            return View(viewModel);
        }

        public ActionResult AppUnavailable(ErrorViewModel viewModel) {
            return View(viewModel);
        }

        public ActionResult Index(ErrorViewModel viewModel) {
            Global.DefaultLog.WarnFormat("[ThreadId: {0}] {1} Url: {2} User: {3}",
                Thread.CurrentThread.ManagedThreadId, Extensions.CurrentMethodName(), System.Web.HttpContext.Current.Request.Url.AbsoluteUri,
                string.IsNullOrWhiteSpace(System.Web.HttpContext.Current.User.Identity.Name) ? "N/A" : System.Web.HttpContext.Current.User.Identity.Name);

            return View(viewModel);
        }

        public ActionResult NotFound(ErrorViewModel viewModel) {
            Global.DefaultLog.WarnFormat("[ThreadId: {0}] {1} Url: {2} User: {3}",
                Thread.CurrentThread.ManagedThreadId, Extensions.CurrentMethodName(), System.Web.HttpContext.Current.Request.Url.AbsoluteUri,
                string.IsNullOrWhiteSpace(System.Web.HttpContext.Current.User.Identity.Name) ? "N/A" : System.Web.HttpContext.Current.User.Identity.Name);

            Response.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
            return View(viewModel);
        }

        public ActionResult Unknown(ErrorViewModel viewModel) {
            Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
            return View(viewModel);
        }

    }
}
